<?php

function validateLogin($u,$p) { 
	$sql  = "SELECT uid from users WHERE username = '".mysql_real_escape_string($u)."' 
	AND password ='".mysql_real_escape_string(sha1($p))."' AND active='1'";
	$result = mysql_query($sql); $GLOBALS['q']++;
	if(!$result) { return FALSE; } 
	$n = mysql_num_rows($result); 
	if($n < 1) { 
		return FALSE; 
	} else { 
		return TRUE;
	}
}

function get_weblog_entries($user, $numposts) { 
	$sql = "SELECT pubdate,teaser,id FROM content WHERE public=1 LIMIT 0,10"; 
	$result = mysql_query($sql); $GLOBALS['q']++;
	while($row = mysql_fetch_assoc($result)) { 
		$x[] = $row; 
	}
	return $x; 
}

function array_to_string($a) { 
	foreach($a as $k => $v) { 
		if(is_array($v)) { 
			array_to_string($v); 
		} else { 
			$p .= $k." => ".$v; 
		} 
	}
	return $p;
}

function record_request($params) { 
	unset($p); 
	$fp = fopen('request.txt','w+'); 
	if(is_array($params)) { 
		$p = array_to_string($params); 
	} else { 
		$p = $params;
	}
	fwrite($fp,$p); 
	fclose($fp); 
}

function record_response($resp) { 
	$fp = fopen('response.txt','w+'); 
	fwrite($fp,$resp); 
	fclose($fp); 
}
?>